export interface WidgetItem {
  name: string;
  width: number;
  height: number;
  x: number;
  y: number;
}
export interface WidgetState {
  widgetMap: Record<string, WidgetItem>;
}
export const widgetState: WidgetState = {
  widgetMap: {},
};
export default {
  state: widgetState,
  mutations: {
    setWidget: (
      state: WidgetState,
      payload: { id: string; item: WidgetItem }
    ) => {
      const { id, item } = payload;
      state.widgetMap[id] = item;
    },
    updateWidgetXY: (
      state: WidgetState,
      payload: { id: string; position: { x: number; y: number } }
    ) => {
      const {
        id,
        position: { x, y },
      } = payload;
      state.widgetMap[id].x = x;
      state.widgetMap[id].y = y;
    },
    updateWidgetWH: (
      state: WidgetState,
      payload: { id: string; size: { w: number; h: number } }
    ) => {
      const {
        id,
        size: { w, h },
      } = payload;
      state.widgetMap[id].width = w;
      state.widgetMap[id].height = h;
    },
  },
};
